import stack
import functionhandler
from frontend import ast

#This class walks the nodes, handing each one to the appropriate handler.
class TreeHandler:
 def __init__(self, stack):  #We want a copy of stack so the creator of this class can see what's going on.
  self.stack=stack #save the stack.
  self.funchand=functionhandler.Functions(self.stack) #handle FunctionCallNode classes.
  self.Node=None

#walk the tree.
 def WalkNodes(self, tree):
  self.node=tree #store the pointer. 
  while isinstance(self.node, ast.Node):
   if isinstance(self.node, ast.ExpressionNode):
    self.stack.push(self.node.Value)
   elif isinstance(self.node, ast.FunctionCallNode):
    self.funchand.HandleNode(self.node)
   self.node=self.node.next
